from socket import *
import os
ip_port=("localhost",1235)
back_log=5
buff_size=1024
html_server = socket(AF_INET, SOCK_STREAM)
basepath = os.path.dirname(__file__)
path1=os.path.join(basepath,"base_html.html")
path=path1.replace('\\','/')
# print(os.path.dirname(__file__))
print(path)
def main():
    html_server.bind(ip_port)
    html_server.listen(back_log)
    while True:
        try:
            conn,addr = html_server.accept()
            conn.recv(buff_size)
            with open(path,'rb') as f:
                data = f.read()
            conn.sendall(bytes("HTTP/1.1 201 OK\r\n\r\n","utf-8")) # http 协议必须有的固定的
            # conn.sendall(bytes("<h>Hello11,World</h>",encoding="utf-8"))
            print(data)
            conn.sendall(data)
            conn.close()
        except Exception as e:
            print(e)


if __name__ == '__main__':
    main()